import Vue from 'vue'
import Router from 'vue-router'
//import home from '@/components/view/public/home'
import homegu from '@/components/public/home_gu'
import login from '@/components/public/login'
import welcome from '@/components/public/welcome'

import teacher_home from '@/components/view/teacher_home' ///教师主页面

import courseware from '@/components/view/courseware' ///导学资源管理

import section from '@/components/view/section' ///章节管理
import score from '@/components/view/score' //成绩管理
import exam from '@/components/view/exam' //课程通知
import courseInform from '@/components/view/courseInform' //考试管理


Vue.use(Router)

let router =new Router({
	routes: [{
			path: '/',
			name: '登陆页',
			component: login
		},
		{
			path: '/login',
			name: '登陆页',
			component: login
		},
		{
			path: '/homegu', //需要键入的浏览器地址
			name: '主页', //当前组件页名字
			redirect: '/welcome', //自动重定向
			component: homegu, //组件名
			leaf: true, //只有一个节点
			iconCls: 'el-icon-menu', //图标样式class

		},
		{
			path: '/welcome',
			component: homegu, //父组件的名字
			name: '主页',
			leaf: true,
			iconCls: 'el-icon-menu',
			children: [{
				path: '/welcome',
				component: welcome,
				name: 'welcome'
			}]
		},
		{
			path: '/',
			component: homegu, //父组件的名字
			name: '教师主页',
			leaf: true,
			iconCls: 'el-icon-menu',
			menuShow: true,
			children: [{
				path: '/teacherhome',
				component: teacher_home,
				name: '教师主页'
			}]
		},

		{
			path: '/',
			component: homegu, //父组件的名字
			name: '导学资源',
			leaf: true,
			iconCls: 'el-icon-menu',
			menuShow: true,
			children: [{
				path: '/courseware',
				component: courseware,
				name: '导学资源'
			}]
		},

		{
			path: '/section',
			component: homegu, //父组件的名字
			name: '主页',
			leaf: true,
			iconCls: 'el-icon-menu',
			menuShow: true,
			children: [{
				path: '/section',
				component: section,
				name: '章节管理'
			}]
		},
		{
			path: '/',
			component: homegu, //父组件的名字
			name: '成绩主页',
			leaf: true,
			iconCls: 'el-icon-menu',
			menuShow: true,
			children: [{
				path: '/score',
				component: score,
				name: '成绩管理'
			}]
		},
		{
        path: '/exam',
        component:homegu, //父组件的名字
        name:'考试管理',
        leaf:true,
        iconCls:'el-icon-menu',
        menuShow:true,
        children: [
          {path: '/exam', component:exam,name:'考试管理'}
        ]
    },
    {
        path: '/courseInform',
        component:homegu, //父组件的名字
        name:'课程通知',
        leaf:true,
        iconCls:'el-icon-menu',
        menuShow:true,
        children: [
          {path: '/courseInform', component:courseInform,name:'课程通知'}
        ]
    }
   





	]
	
	
})
router.beforeEach((to, from, next) => {
  let stu = JSON.parse(window.localStorage.getItem('teacher-user'));
       if(to.path == '/login' && stu != null){
            if (stu.rememberMe == true) {
              next({ path: '/home' });
           }else{
               window.localStorage.removeItem("teacher-user");
               next({ path: '/login' });
           }
       }
       if (stu == null && to.path != '/login') {
           next({ path: '/login' })
       } else {
           next()
       }

})
export default router;
